// main.c
#include "definitions.h"
#include "../custom/clock/clock.h"
#include "../custom/inc/app_led.h"
#include "../custom/inc/app_print.h"
#include "../custom/inc/cli_core.h"
#include "../custom/inc/serial_service.h"
#include "../custom/inc/st7735.h"

const Command g_cli_commands[] = {{"led", LED_parse, "set LED mode"},
                                  {"print", print_parse, "print string, number or memory"},
                                  {"help", cli_help, "print help info"},
                                  //   {"button", Button_Parse, "button -l/-r/-u/-b/-o/-c: 控制方向与操作"},
                                  //   {"game1", Gomoku_Parse, "game1 -s: 开始五子棋"},
                                  //   {"game2", Sokoban_Parse, "game2 -s: 开始推箱子"},

                                  {NULL, NULL, NULL}};

int main(void)
{
    SYS_Initialize(NULL);
    SYSTICK_TimerStart();
    Serial_Init();
    LED_PWM_Init();
    registerCommands(g_cli_commands);
    ST7735_Init();
    RTC_Init();
    SYSTICK_DelayMs(100);
    Serial_Printf("CLI System Ready\r\n");
    ST7735_FillScreen(COLOR_BLACK);
    uint32_t lastTime    = 0;
    uint32_t currentTime = 0;
    uint8_t  displayMode = 0;

    while (true)
    {
        currentTime = SYSTICK_GetTickCounter();
        if ((currentTime - lastTime) > 2000)
        {
            displayMode = !displayMode;
            lastTime    = currentTime;
        }
        if (displayMode)
        {
            ST7735_FillScreen_Ikun(); // 显示IKUN
        }
        else
        {
            Clock_Task(); // 显示时钟
        }

        Serial_Task();      // 串口主任务
        LED_StateMachine(); // LED 状态机更新
        ST7735_Task();      // 刷新屏幕
        SYSTICK_DelayMs(10);
    }

    return EXIT_FAILURE;
}